package com.burgeon.backend.Rest.coupon.util;
/**
 * 通过开卡店仓查询会员xx
 */

import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindVIPByStore extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public FindVIPByStore(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public ArrayList<String> getData(String message) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(message), url);

        String code = new JSONArray(str).getJSONObject(0).getString("code");

        if (!"0".equals(code)){
            throw new Exception("接口获取数据失败");
        }

        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        ArrayList<String> data = new ArrayList<String>();

        for (int i = 0; i < jsonArray.length(); i++) {
            data.add(jsonArray.getJSONArray(i).getString(0));
        }
        System.err.println(data.size());
        return data;
    }

    private MultiValueMap Data(String message) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("CARDNO");

        params.put("columns", columns);
        params.put("table", "C_VIP");//表名

        HashMap paramss = new HashMap();
        String ac = "'="+message+"'";
        paramss.put("column", "'C_STORE_ID;NAME'");
        paramss.put("condition", ac);
        params.put("params", paramss);
        params.put("count","true");

        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        FindVIPByStore g = new FindVIPByStore("39.100.45.8:55322", "nea@burgeon.com.cn", "123");
        try {
            System.err.println(g.getData("廊坊万达店"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
